using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.ServiceModel.DomainServices.Client.ApplicationServices;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Navigation;
using YouFood.LoginUI;
using YouFood.Views.Login;

namespace YouFood
{
    public partial class Home : Page
    {
        #region Property

        private YouFoodLoginForm YouFoodLoginForm { get; set; }

        #endregion

        public Home()
        {
            InitializeComponent();
            this.img1.Source = new BitmapImage(new Uri("/YouFood;component/Assets/Images/Cooker.png", UriKind.Relative));
            this.img2.Source = new BitmapImage(new Uri("/YouFood;component/Assets/Images/Waiter.png", UriKind.Relative));
            this.img3.Source = new BitmapImage(new Uri("/YouFood;component/Assets/Images/Admin.png", UriKind.Relative));
        }

        // Executes when the user navigates to this page.
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            if(!WebContext.Current.User.IsAuthenticated)
                ManageLogin();
        }

        private void ManageLogin()
        {
            YouFoodLoginForm = new YouFoodLoginForm();

            // NAvigation apres mot de passe
            YouFoodLoginForm.Logged += (obj, j) =>
                                           {
                                               if (WebContext.Current.User.IsInRole("Cuisinier"))
                                               {
                                                   NavigationService.Navigate(new Uri("CookerView", UriKind.Relative));
                                               }
                                               if (WebContext.Current.User.IsInRole("Serveur"))
                                               {
                                                   NavigationService.Navigate(new Uri("WaiterView", UriKind.Relative));
                                               } 
                                               if (WebContext.Current.User.IsInRole("Admin"))
                                               {
                                                   NavigationService.Navigate(new Uri("AdminView", UriKind.Relative));
                                               }
                                           };
            YouFoodLoginForm.Show();
        }

    }
}
